﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Compilex.Automata
{
    [global::System.Serializable]
    public class UnrecognizedInputException : Exception
    {
        //
        // For guidelines regarding the creation of new exception types, see
        //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconerrorraisinghandlingguidelines.asp
        // and
        //    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp07192001.asp
        //

        public UnrecognizedInputException() { }
        public UnrecognizedInputException(string input) :
            base(PrepareMessage(input)) { }

        private static string PrepareMessage(string input)
        {
            string prefix = "A entrada não foi reconhecida: \"";
            if (input.Length > 50)
                prefix += input.Substring(0, 50) + "...";
            else
                prefix += input;
            return prefix + "\"";
        }
        public UnrecognizedInputException(string input, Exception inner) : base(
            PrepareMessage(input), inner) { }
        protected UnrecognizedInputException(
          System.Runtime.Serialization.SerializationInfo info,
          System.Runtime.Serialization.StreamingContext context)
            : base(info, context) { }
    }
}
